const app = getApp();
var openid = wx.getStorageSync('openid');
var util = require('../../utils/util.js');
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    url:{
      type:String,
      value:'',
    },
    extendId:{
      type:String,
      value:'',
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    commentList : [],
    commentTotal:0,
    news:'',
    baike:'',
    dynamic:''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /*初始化列表数据*/
    initData: function () {
      var openid = wx.getStorageSync('openid');
      var that = this;
      var type = that.properties.url;
      var extendId = that.properties.extendId;
      that.setData({
        page: 1,
      });
      wx.request({
        url: app.config.serverCfg.domain.commentMain,
        method: 'post',
        header: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: {
          openid: openid,
          page: that.data.page,
          type:type,
          extendId:extendId,
        },
        success: function (res) {
          that.setData({
            commentList: res.data.data,
            commentTotal:res.data.total,
          })
        }
      });
    },
    /**
     * 刚发布的时候，静态追加在评论的顶层
     */
    addData:function(data){
      var that = this;
      var datetime = util.formatTime(new Date());
      data.ctime = datetime;

      that.data.commentList = that.data.commentList.concat(data);
      that.setData({
        commentList: that.data.commentList,
        commentTotal: that.data.commentTotal+1,
      })
    }
  }
})
